import numpy as np
import numpy as ny

# t1=ny.arange(20).reshape(4,5)
# print(t1)
# print('*'*100)

# # 取行,从0开始的
# print(t1[0])
#
# # 取连续多行 从第三行开始的
# print('*'*100)
# print(t1[2:])
#
# # 取不连续的多行 用[]
# print('*'*100)
# print(t1[[0,2,3]])

# # 取列
# print('*'*100)
# print(t1[:,0])
#
# # 取连续的多列
# print('*'*100)
# print(t1[:,2:])
#
# # 取不连续的多列
# print('*'*100)
# print(t1[:,[0,2,3]])
#
# # 取行和列,取第1行,第2列的数据
# print('*'*100)
# a=t1[0,1]
# print(type(a))
#
# # 取多行和多列,取第一行到第三行,第2列到第4列的结果
# print('*'*100)
# b=t1[0:3,1:4]
# print(b)

# # 取多个不相邻的点
# # 选出来的是(0,1) (2,2)
# print('*'*100)
# c=t1[[0,2],[1,2]]
# print(c)
#
# t1[t1<3]=2
# print(t1)
# t1[t1>10]=20
# print(t1)

# t2=np.where(t1<=10,0,10)
# print(t2)
#
# t3=t1.clip(10,18) # 小于10 的换成10,大于18的换成18
# print(t3)
#
# t1=t1.astype(float)
# t1[3,3]=np.nan
# print(t1)
#
# t1[:,0]=0
# print(t1)
#
# print(np.count_nonzero(t1)) #不为0的数
# print(np.count_nonzero(t1!=t1))  #nan的个数
# print(np.count_nonzero(np.isnan(t1)))
# print(np.sum(t1))
# t2=np.arange(12).reshape(3,4)
# print(np.sum(t2,axis=0)) # 按行加列的
# print(np.sum(t2,axis=1)) # 按列加行的
# print(np.sum(t1,axis=0))

# t1=t1.astype(float)
# t1[3,3]=np.nan
# print(t1)

# print(t1.sum(axis=0))  # 求每列的总和,按行分
# print(t1.mean(axis=0))  # 求每列的均值
# print(t1.max(axis=0))  # 计算一列的最大值
# print(t1.min(axis=0))  # 计算一列的最小值
# print(np.ptp(t1,axis=0))  # 极值,即最大值和最小值的差
# print(t1.std(axis=0))    # 标准差
# t2=np.array([1,1,1,1])
# print(t2.std())

# # 将nan替换为它的均值
# t1=np.arange(12).reshape(3,4)
# t1=t1.astype(float)
# t1[1,2:]=np.nan
# print(t1)
#
# for i in range(t1.shape[1]):  # shape表示形状 shape[1]表示列
#     temp_col=t1[:,i]
#     nan_num=np.count_nonzero(temp_col!=temp_col)
#     if nan_num!=0:
#         temp_not_nan_col=temp_col[temp_col==temp_col]
#         temp_col[np.isnan(temp_col)]=np.mean(temp_not_nan_col)
#
# print(t1)

# # 数组的拼接
# t1=np.arange(12).reshape(3,4)
# t2=np.arange(12,24).reshape(3,4)
# # print(t1)
# # print(t2)
# # t3=np.vstack((t1,t2))
# # print(t3)
# # print(np.hstack((t1,t2)))
# zero_data=np.zeros((t1.shape[0],1)).astype(int)
# ones_data=np.ones((t2.shape[0],1)).astype(int)
# t1=np.hstack((t1,zero_data))
# t2=np.hstack((t2,ones_data))
# data=np.vstack((t1,t2))
# print(data)
# print(np.eye(3))
#
# # t3=data
# # t3[0,0]=100
# # print(data)
# t3=data.copy()
# t3[0,0]=100
# print(data)

# def fun(t):
#     for i in range (t.shape[1]):
#         col=t[:,i] #取出当前的一列
#         nan_num=np.count_nonzero(col)
#         if nan_num != 0:
#             col_not_nan=col[col==col]
#             avg=np.mean(col_not_nan)
#             col[col!=col]=avg
#
# if __name__ == '__main__':
#     t=np.arange(12).reshape(3,4).astype(float)
#     t[1,2:]=np.nan
#     print(t)
#     print('*'*100)
#     fun(t)
#     print(t)

t=np.arange(12).reshape(3,4)
print(t)
print(t[1])
print(t[1:,:2])